package com.wl.application.service.impl;

import com.wl.application.entity.User;
import com.wl.application.feign.api.UserApi1;
import com.wl.application.feign.api.UserApi2;
import com.wl.application.feign.api.UserApi3;
import com.wl.application.service.UserService;
import io.seata.spring.annotation.GlobalTransactional;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

/**
 * @author wl
 * @version 1.0
 * @date 2022/8/1
 * @description:
 */
@Service
@Slf4j
public class UserServiceImpl  implements UserService {
    @Autowired
    private UserApi1 userApi1;

    @Autowired
    private UserApi2 userApi2;

    @Autowired
    private UserApi3 userApi3;

    @Override
    @GlobalTransactional(timeoutMills = 600000)
    public String save(User user) {
        //1.向数据库1添加数据
        log.debug("server1开始执行");
        userApi1.save(user);
        log.debug("server1结束执行");
        int b=10/user.getAge();
        //2.向数据库2添加数据
        log.debug("server2开始执行");
        userApi2.save(user);
        log.debug("server2结束执行");

        //3.向数据库3添加数据
        log.debug("server3开始执行");
        userApi3.save(user);
        log.debug("server3结束执行");

        return "invoke:save";
    }
}
